﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Kaio.Core
{
    public class Utils
    {
        #region RandomPassword


        public static string RandomNumber(int length)
        {
            return Random(length, true);
        }

        public static string Random(int length, bool onlyNumber)
        {
            string PASSWORD_CHARS = onlyNumber ? "0123456789" : "123456789ABCDEFGHJKLMNPQRSTWXYZ";
            var s = new StringBuilder();
            char[] chars = PASSWORD_CHARS.ToCharArray();
            var _rd = new Random();
            for (int i = 0; i < length; i++)
            {
                int index = _rd.Next(chars.Length - 1);
                s.Append(chars[index].ToString());
            }
            return s.ToString();

        }

        #endregion

        #region File


        public static string ReadFileToString(string filePath)
        {
            return File.ReadAllText(filePath, Encoding.UTF8);

        }

        public static void WriteStringToFile(string content, string filePath)
        {
            using (StreamWriter w = File.AppendText(filePath))
            {

                try
                {
                    w.Write(content);
                    w.Flush();
                }
                finally
                {
                    w.Close();
                }

            }

        }
        #endregion
    }
}
